package com.gzsxy.esjy.service.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gzsxy.esjy.bus.log.annotation.OperLog;
import com.gzsxy.esjy.bus.log.enum1.LogActionType;
import com.gzsxy.esjy.service.base.dto.request.ApiOrderRequest;
import com.gzsxy.esjy.service.base.dto.response.DefaultResponse;

import com.gzsxy.esjy.service.base.dto.response.OrderCountRsp;
import com.gzsxy.esjy.service.base.dto.response.OrderProductRsp;
import com.gzsxy.esjy.service.base.dto.response.OrderRsp;
import com.gzsxy.esjy.service.base.util.Page;
import com.gzsxy.esjy.service.order.entity.vo.OrderQueryVo;
import com.gzsxy.esjy.service.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 订单管理
 * @date 2022/2/17 17:44
 */
@CrossOrigin  //解决跨域
@RefreshScope    //动态刷新配置文件-外部配置文件
@RestController
@RequestMapping("/admin/order")
@Api("订单管理")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/list")
    @ApiOperation("分页查询")
    public DefaultResponse page(Page<?> page, OrderQueryVo orderQueryVo){
        IPage<OrderRsp> list = orderService.getPageVo(page,orderQueryVo);
        return DefaultResponse.ok(list);
    }


    @PutMapping("/{orderId}")
    @ApiOperation("改变订单状态")
    @OperLog(operModul = "订单管理",operType = LogActionType.UPDATE,operDesc = "改变订单状态")
    public DefaultResponse eidtStatus(@PathVariable String orderId,@RequestBody ApiOrderRequest apiOrderRequest){
        orderService.eidtStatus(orderId,apiOrderRequest.getStatus());
        return DefaultResponse.ok();
    }


    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除订单")
    @OperLog(operModul = "订单管理",operType = LogActionType.DELETE,operDesc = "删除订单")
    public DefaultResponse deleteOrder(@PathVariable String id){
        orderService.deleteOrder(id);
        return DefaultResponse.ok();
    }


    @GetMapping("/getByCount")
    @ApiOperation("查询当前订单列表各个状态的数量")
    public DefaultResponse getStatusCount(){
        OrderCountRsp orderCountRsp= orderService.getStatusCount();
        return DefaultResponse.ok(orderCountRsp);
    }


    @GetMapping("/getNum")
    @ApiOperation("根据当日时间统计不同商家订单数和当日销量")
    public DefaultResponse getOrderStatistical(@RequestParam String day){
        List<OrderCountRsp> orderCountRsp = orderService.getOrderStatistical(day);
        return DefaultResponse.ok(orderCountRsp);
    }



}
